
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JColorChooser;

public class ventanaPoligonos extends javax.swing.JFrame {//soy un jframe

    areaDibujo areaDibujo = new areaDibujo();
    
    public ventanaPoligonos() {
        initComponents();
        
      
        this.setTitle("Dibujo de Poligonos");
        
        areaDibujo.setBackground(Color.WHITE);
        this.add(areaDibujo);

        //polilinea.add(null);
    }
    
    public void paint(Graphics g) {
        super.paintComponents(g);

        areaDibujo.setBounds(200, 100, this.getBounds().width - 250, this.getBounds().height - 150);



    } 

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jRBcerrarfig = new javax.swing.JRadioButton();
        jButton2 = new javax.swing.JButton();
        jRBDibujoCoordenadas = new javax.swing.JRadioButton();
        jRBDibujoManual = new javax.swing.JRadioButton();
        jButton3 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        valueStroke = new javax.swing.JSpinner();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                formMouseReleased(evt);
            }
        });
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });

        jRBcerrarfig.setText("Cerrar figura");
        jRBcerrarfig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRBcerrarfigActionPerformed(evt);
            }
        });

        jButton2.setText("dibujo Libre");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRBDibujoCoordenadas);
        jRBDibujoCoordenadas.setSelected(true);
        jRBDibujoCoordenadas.setText("Dibujo Por Coordenadas");
        jRBDibujoCoordenadas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRBDibujoCoordenadasActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRBDibujoManual);
        jRBDibujoManual.setText("Dibujo Manual");
        jRBDibujoManual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRBDibujoManualActionPerformed(evt);
            }
        });

        jButton3.setText("BORRAR TODO");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jTextField1.setEditable(false);
        jTextField1.setBackground(new java.awt.Color(51, 51, 51));
        jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField1MouseClicked(evt);
            }
        });

        valueStroke.setModel(new javax.swing.SpinnerNumberModel(1, 1, 10, 1));
        valueStroke.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                valueStrokeStateChanged(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Continua", "Punteada 1", "punteada2" }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sin relleno", "Solido", "Gradiente", "Texturizado" }));
        jComboBox2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox2ItemStateChanged(evt);
            }
        });
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jLabel1.setText("Estilo de linea");

        jLabel2.setText("Estilo de relleno");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(96, 96, 96)
                        .addComponent(jRBDibujoCoordenadas)
                        .addGap(18, 18, 18)
                        .addComponent(jRBDibujoManual))
                    .addComponent(jRBcerrarfig)
                    .addComponent(jButton2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(valueStroke, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRBDibujoManual)
                        .addComponent(jRBDibujoCoordenadas))
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jRBcerrarfig)
                .addGap(18, 18, 18)
                .addComponent(jButton2)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(valueStroke, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(47, 47, 47)
                .addComponent(jButton3)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRBcerrarfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRBcerrarfigActionPerformed
        // TODO add your handling code here:

        if (jRBcerrarfig.isSelected()) {
            areaDibujo.setcerrarDibujo(true);
        } else {
         
            areaDibujo.setcerrarDibujo(false);
        }


    }//GEN-LAST:event_jRBcerrarfigActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        
        areaDibujo.getArrayListCoordenadas().clear();//obtenemos coordenadas y limpiamos puntos.

        FiguraManual fManual = new FiguraManual(areaDibujo.getArrayListCoordenadas(), areaDibujo);
        fManual.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        fManual.setSize(400, 400);
        fManual.setVisible(true);
        
        areaDibujo.setGuardaDibujo(true);//probar dentro de frame fmanual.....***********
    }//GEN-LAST:event_jButton2ActionPerformed

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
    }//GEN-LAST:event_formMouseClicked

    private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_formMousePressed

    private void formMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseReleased
    }//GEN-LAST:event_formMouseReleased

    private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged
    }//GEN-LAST:event_formMouseDragged

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
    }//GEN-LAST:event_formMouseMoved

    private void jRBDibujoCoordenadasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRBDibujoCoordenadasActionPerformed
        // TODO add your handling code here:
        jButton2.setEnabled(true);
        areaDibujo.setDibujando(false);
        areaDibujo.setdibCoordenadas(true);
        areaDibujo.setDibujoManual(false);
        areaDibujo.getArrayListCoordenadas().clear();
        
    }//GEN-LAST:event_jRBDibujoCoordenadasActionPerformed

    private void jRBDibujoManualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRBDibujoManualActionPerformed
        // TODO add your handling code here:
        jButton2.setEnabled(false);
        areaDibujo.setDibujoManual(true);
        areaDibujo.setdibCoordenadas(false);
        areaDibujo.setInicioPolilinea(true); //activamos a inicio polilinea cuando entramos a modo manual.
        
        
    }//GEN-LAST:event_jRBDibujoManualActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:

        areaDibujo.getArrListFiguras().clear();
        areaDibujo.getTrazoPolilinea().reset();
        areaDibujo.getArrayListCoordenadas().clear();
        areaDibujo.repaint();



    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1MouseClicked
        // TODO add your handling code here:
        areaDibujo.setColor(JColorChooser.showDialog(ventanaPoligonos.this, "Seleccione color", areaDibujo.getColor()));
        if (areaDibujo.getColor() == null) {
            areaDibujo.setColor(Color.BLACK);
        }
        jTextField1.setBackground(areaDibujo.getColor());


    }//GEN-LAST:event_jTextField1MouseClicked

    private void valueStrokeStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_valueStrokeStateChanged
        // TODO add your handling code here:
        areaDibujo.setGrosor(Integer.parseInt(valueStroke.getValue().toString()));


    }//GEN-LAST:event_valueStrokeStateChanged

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
        // TODO add your handling code here:

        areaDibujo.setIndexEstilo(jComboBox1.getSelectedIndex());


    }//GEN-LAST:event_jComboBox1ItemStateChanged

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ActionPerformed

    private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox2ItemStateChanged
        // TODO add your handling code here:
        areaDibujo.setIndexRelleno( jComboBox2.getSelectedIndex());

    }//GEN-LAST:event_jComboBox2ItemStateChanged

    public static void main(String args[]) {

        ventanaPoligonos ventana = new ventanaPoligonos();

        ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ventana.setExtendedState(JFrame.MAXIMIZED_BOTH);//abre la ventana maximizada.

        ventana.setVisible(true);

    }

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton jRBDibujoCoordenadas;
    private javax.swing.JRadioButton jRBDibujoManual;
    private javax.swing.JRadioButton jRBcerrarfig;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JSpinner valueStroke;
    // End of variables declaration//GEN-END:variables
}
